<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Login extends CI_Controller {
// 
//  login.php
//  phpweb
//  
//  Created by WillLee on 2011-06-28.
//  Copyright 2011 lishuzu. All rights reserved.
// 


	function __construct()
	{
		parent::__construct();
		$this->load->model('user_model');
	}
	
	public function index()
	{
		$data = array();
		if ($this->session->userdata('user')) {
			showmessage('自动登录成功', 'home/index', 1);
		}
		if (submitcheck('login')) {
			$username = $this->input->post('username', true);
			$password = $this->input->post('password', true);
			$userinfo = $this->user_model->getuser('username', $username);
			// 摧毁session
			$this->session->sess_destroy();
			$password = md5(md5($password).$userinfo['salt']);
			if ($password === $userinfo['password']) {
				if ($userinfo['status'] == 1) {
					showmessage('该账户已经被冻结，请联系管理员。', 'index', 1);
				}
				$session_data = array(
					'user' => $userinfo
					);
				$this->session->set_userdata($session_data);
				showmessage('登录成功', 'home/index', 1);
			}else{
				showmessage('用户名或密码错', 'login/index', 1);
			}
		}
		$this->load->template('login_tpl',$data);
	}
}

/* End of file index.php */
/* Location: ./application/controllers/index.php */